home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / hard / drivr / serpat20.lha / SerialPatch.asm < prev    next >
Assembly Source File  |  1992-10-01  |  12KB  |  325 lines

  1. ;****** Auto-Revision Header (do not edit) *******************************
  2. ;*
  3. ;* © Copyright by PetiWare - freely distributyble software
  4. ;*
  5. ;* Filename         : SerialPatch.asm
  6. ;* Created on       : 24-Aug-92
  7. ;* Created by       : Peter Simons
  8. ;* Current revision : V2.000
  9. ;*
  10. ;*
  11. ;* Purpose: Patches the OpenDevice()-Routine to use any device instead
  12. ;*          of the serial.
  13. ;*
  14. ;*
  15. ;* V2.000 : Released:                           Peter Simons (24-Aug-92)
  16. ;*
  17. ;* V1.003 : added a delay before releasing the memory of NewOpenDev(),
  18. ;*          because this could cause problems, when the routine is in
  19. ;*          use, while the patch is removed.
  20. ;*
  21. ;* V1.002 : NewUnit-switch added
  22. ;*
  23. ;* V1.001 : PatchOnlyUnit-switch added
  24. ;*
  25. ;* V1.000 : released:                           Peter Simons (24-Aug-92)
  26. ;*
  27. ;* V0.300 : Argument-Parsing implemented
  28. ;*
  29. ;* V0.200 : Main patch-routine works
  30. ;*
  31. ;* V0.100 : Patch based on my CPUClear V2.011
  32. ;*
  33. ;* V0.000 : --- Initial release ---
  34. ;*
  35. ;*************************************************************************
  36. ;
  37. ;
  38.  
  39. ;***************************************************************************
  40. ;*                                                                         *
  41. ;* SEKTION: Labels, Macros, Switches, Structures                           *
  42. ;*                                                                         *
  43. ;***************************************************************************
  44.  
  45. ;-------------------------------------- Switches -----------
  46.                 MC68000
  47.                 EXEOBJ
  48.                 OBJFILE "RAM:SerialPatch"
  49.                 NEWSYNTAX
  50.                 MULTIPASS
  51.  
  52. ;-------------------------------------- Exec ---------------
  53. MEMF_PUBLIC     equ     1<<0
  54.  
  55. ;-------------------------------------- Labels -------------
  56.                 MACLIB  "DATAS:Offsets.preass"
  57. KICKVERSION     equ     37
  58.  
  59. _DOSBase        equr    A5
  60. _NewOpenDev     equr    A3
  61. _OutputHandle   equr    D7
  62. _RDArgsStruct   equr    D6
  63.  
  64. ;-------------------------------------- Macros -------------
  65. REVISION        MACRO
  66.                 dc.b "2.000"
  67.                 ENDM
  68. REVDATE         MACRO
  69.                 dc.b "24-Aug-92"
  70.                 ENDM
  71.  
  72.  
  73.  
  74. ;***************************************************************************
  75. ;*                                                                         *
  76. ;* SEKTION: Program                                                        *
  77. ;*                                                                         *
  78. ;***************************************************************************
  79.  
  80. START:          lea     (DATA,PC),a4
  81.                 BASEREG A4,DATA
  82.                 OPTIMON BASEREG
  83.  
  84.                 move.l  ($4).W,a6
  85.                 lea     (dosname,PC),a1
  86.                 moveq   #KICKVERSION,d0
  87.                 jsr     (_LVOOpenLibrary,a6)            ; open Dos-Library
  88.                 tst.l   d0
  89.                 beq     .ErrorExit
  90.                 move.l  d0,_DOSBase
  91.  
  92.                 move.l  _DOSBase,a6
  93.                 lea     (Template,PC),a0
  94.                 move.l  a0,d1
  95.                 lea     (_NewDeviceName,PC),a2
  96.                 move.l  a2,d2
  97.                 moveq   #0,d3
  98.                 jsr     (_LVOReadArgs,a6)
  99.                 move.l  d0,_RDArgsStruct
  100.                 bne.b   .ArgsOkay
  101.                 pea     (.CloseDosLib,PC)
  102.                 bra     _ErrorHandle
  103.  
  104. .ArgsOkay       move.l  _DOSBase,a6
  105.                 jsr     (_LVOOutput,a6)                 ; get standard-
  106.                 move.l  d0,_OutputHandle                ; outputhandle
  107.  
  108.                 move.l  _OutputHandle,d1
  109.                 beq.b   .SkipWrite
  110.                 lea     (Header,PC),a0                  ; write standard-
  111.                 move.l  a0,d2                           ; header
  112.                 moveq   #Header_len,d3
  113.                 jsr     (_LVOWrite,a6)
  114.  
  115. .SkipWrite      move.l  ($4).w,a6
  116.                 move.l  (_LVOOpenDevice+2,a6),_NewOpenDev ; is the patch
  117.                 cmp.l   #'SPAT',(new_ID,_NewOpenDev)    ; already installed?
  118.                 beq     .RemovePatch                    ; Yep->remove
  119.  
  120. ;-------------------------------------- install patch ------
  121.  
  122.                 lea     (_NewDeviceName,PC),a0
  123.                 tst.l   (a0)
  124.                 bne.b   .ArgOkay
  125.                 moveq   #116,d0         ; REQUIRED_AGUMENT_MISSING
  126.                 pea     (.FreeArgs,PC)
  127.                 bra     _PrintError
  128.  
  129. .ArgOkay        move.l  (a0),a0
  130.                 bsr     _Len
  131.                 add.l   #NewOpenDev_len,d0
  132.                 moveq   #MEMF_PUBLIC,d1
  133.                 move.l  ($4).W,a6
  134.                 jsr     (_LVOAllocVec,a6)
  135.                 tst.l   d0
  136.                 bne.b   .BufferOkay
  137.                 pea     (.FreeArgs,PC)
  138.                 moveq   #103,d0                 ; NO_FREE_STORE
  139.                 bra     _PrintError
  140.  
  141. .BufferOkay     move.l  d0,_NewOpenDev
  142.                 lea     (NewOpenDev,PC),a0
  143.                 move.l  _NewOpenDev,a1          ; copy patch into
  144.                 moveq   #NewOpenDev_len,d0      ; reserved buffer
  145.                 jsr     (_LVOCopyMem,a6)
  146.  
  147.                 tst.l   (_PatchOnlyUnit)
  148.                 beq.b   .NoOnlyUnit
  149.                 move.l  (_PatchOnlyUnit,PC),a0
  150.                 move.l  (a0),(new_PatchOnlyUnit,_NewOpenDev)
  151.  
  152. .NoOnlyUnit     tst.l   (_NewUnit)
  153.                 beq.b   .NoNewUnit
  154.                 move.l  (_NewUnit,PC),a0
  155.                 move.l  (a0),(new_NewUnit,_NewOpenDev)
  156.  
  157. .NoNewUnit      move.l  (_NewDeviceName,PC),a0
  158.                 bsr     _Len
  159.                 lea     (new_NewDevName,_NewOpenDev),a1 ; copy new device-
  160.                 jsr     (_LVOCopyMem,a6)                ; name into reserved
  161.                                                         ; buffer
  162.                 jsr     (_LVOForbid,a6)
  163.                 move.l  ($4).w,a1
  164.                 move.w  #_LVOOpenDevice,a0              ; patch OS-function
  165.                 move.l  _NewOpenDev,d0
  166.                 jsr     (_LVOSetFunction,a6)
  167.                 move.l  d0,(new_OldOpenDev,_NewOpenDev) ; save old vector
  168.                 jsr     (_LVOCacheClearU,a6)            ; flush caches for
  169.                 jsr     (_LVOPermit,a6)                 ; '40 compatiblity
  170.  
  171.                 lea     (Install,PC),a0                 ; give feedback :-)
  172.                 moveq   #Install_len,d3
  173.                 bra.b   .exit
  174.  
  175. ;-------------------------------------- remove patch -------
  176. .RemovePatch    move.l  ($4).w,a1
  177.                 move.w  #_LVOOpenDevice,a0
  178.                 move.l  (new_OldOpenDev,_NewOpenDev),d0
  179.                 move.l  ($4).W,a6
  180.                 jsr     (_LVOSetFunction,a6)            ; replace old
  181.                 move.l  d0,a2                           ; function and
  182.                                                         ; release memory
  183.                 move.l  _DOSBase,a6                     ; after a delay
  184.                 moveq   #100,d1
  185.                 jsr     (_LVODelay,a6)
  186.  
  187.                 move.l  a2,a1
  188.                 move.l  ($4).W,a6
  189.                 jsr     (_LVOFreeVec,a6)
  190.  
  191.                 move.l  _DOSBase,a6
  192.                 lea     (Remove,PC),a0
  193.                 moveq   #Remove_len,d3
  194.  
  195. ;-------------------------------------- exit gracefully ----
  196.  
  197. .exit           move.l  _OutputHandle,d1
  198.                 beq.b   .FreeArgs
  199.                 move.l  a0,d2
  200.                 move.l  _DOSBase,a6
  201.                 jsr     (_LVOWrite,a6)
  202.  
  203.                 move.l  _OutputHandle,d1
  204.                 lea     (Returns,PC),a0
  205.                 move.l  a0,d2
  206.                 moveq   #Returns_len,d3
  207.                 jsr     (_LVOWrite,a6)
  208.  
  209. .FreeArgs       move.l  _RDArgsStruct,d1
  210.                 move.l  _DOSBase,a6
  211.                 jsr     (_LVOFreeArgs,a6)
  212.  
  213. .CloseDosLib    move.l  ($4).W,a6               ; close resources
  214.                 move.l  _DOSBase,a1
  215.                 jsr     (_LVOCloseLibrary,a6)
  216.  
  217. .ErrorExit      moveq   #0,d0
  218.                 rts
  219.  
  220. ;***************************************************************************
  221. ;*                                                                         *
  222. ;* SEKTION: Subroutines                                                    *
  223. ;*                                                                         *
  224. ;***************************************************************************
  225. _ErrorHandle:   move.l  _DOSBase,a6
  226.                 jsr     (_LVOIoErr,a6)
  227. _PrintError:    move.l  d0,d1
  228.                 moveq   #0,d2
  229.                 move.l  _DOSBase,a6
  230.                 jmp     (_LVOPrintFault,a6)
  231.  
  232.  
  233. _Len:           pea     (a0)            ; save register
  234. .loop           tst.b   (a0)+
  235.                 bne.b   .loop           ; currect char equal zero?
  236.                 move.l  a0,d0
  237.                 move.l  (SP)+,a0
  238.                 sub.l   a0,d0           ; return string-length INCLUDING
  239.                 rts                     ; the ZERO-byte
  240.  
  241.  
  242. ;***************************************************************************
  243. ;*                                                                         *
  244. ;* SEKTION: new OpenDev()-Routine                                          *
  245. ;*                                                                         *
  246. ;***************************************************************************
  247. NewOpenDev:
  248. saveregs        setrl   a0-a1
  249.                 movem.l saveregs,-(SP)
  250.  
  251.                 lea     (.PatchOnlyUnit,PC),a1
  252.                 cmp.w   #-1,(a1)
  253.                 beq.b   .Cmp
  254.                 cmp.l   (a1),d0
  255.                 bne.b   .OpenNormal
  256.  
  257. .Cmp            lea     (.SerDeviceName,PC),a1
  258. .CmpLoop        tst.b   (a0)                    ; compare device-name with
  259.                 beq.b   .PatchIt                ; the specified one (default
  260.                 cmpm.b  (a0)+,(a1)+             ; is serial.device) and
  261.                 bne.b   .OpenNormal             ; replace it if it's the
  262.                 bra.b   .CmpLoop                ; same
  263.  
  264. .PatchIt        lea     (.NewUnit,PC),a0
  265.                 cmp.l   #-1,(a0)
  266.                 beq.b   .NoNewUnit
  267.  
  268.                 movem.l (SP)+,saveregs
  269.                 lea     (.NewDeviceName,PC),a0
  270.                 move.l  (.NewUnit,PC),d0
  271.                 bra.b   .OldOpenDev
  272.  
  273. .NoNewUnit      movem.l (SP)+,saveregs
  274.                 lea     (.NewDeviceName,PC),a0
  275.                 bra.b   .OldOpenDev
  276.  
  277. .OpenNormal     movem.l (SP)+,saveregs
  278.  
  279. new_OldOpenDev  equ     (*-NewOpenDev+2)
  280. .OldOpenDev     jmp     ($00000000).L
  281. new_ID          equ     (*-NewOpenDev)
  282.                 dc.b    "SPAT"
  283. new_PatchOnlyUnit       equ     (*-NewOpenDev)
  284. .PatchOnlyUnit  dc.l    -1
  285. new_NewUnit     equ     (*-NewOpenDev)
  286. .NewUnit        dc.l    -1
  287. .SerDeviceName  dc.b    "serial.device",0
  288. new_NewDevName  equ     (*-NewOpenDev)
  289. .NewDeviceName
  290.  
  291. NewOpenDev_len  equ     (*-NewOpenDev)          ; length of routine
  292.  
  293. ;***************************************************************************
  294. ;*                                                                         *
  295. ;* SEKTION: Daten, Zeiger                                                  *
  296. ;*                                                                         *
  297. ;***************************************************************************
  298. DATA:
  299.  
  300. dosname         dc.b    "dos.library",0
  301. Header          dc.b    $9B,"1;33",$6D
  302.                 dc.b    "$VER: SerialPatch "
  303.                 REVISION
  304.                 dc.b    " ("
  305.                 REVDATE
  306.                 dc.b    ")"
  307.                 dc.b    $9B,$6D
  308.                 dc.b    " coding by Peter Simons",$0A
  309. Header_len      equ     (*-Header)
  310.  
  311. Install         dc.b    "Installed"
  312. Install_len     equ     (*-Install)
  313. Remove          dc.b    "Removed"
  314. Remove_len      equ     (*-Remove)
  315. Returns         dc.b    "...",$0A,$0A
  316. Returns_len     equ     (*-Returns)
  317.  
  318. Template        dc.b    "NewDevice,POU=PatchOnlyUnit/N,NewUnit/N",0
  319.  
  320. _NewDeviceName  ds.l    1
  321. _PatchOnlyUnit  ds.l    1
  322. _NewUnit        ds.l    1
  323.  
  324.                 END
  325.